package fastjsonDemo.JSONDemo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import fastjsonDemo.JSONDemo.pojo.User;
import org.junit.Test;

import java.math.BigDecimal;

/**
 * 序列化特性的使用
 */
public class SerializePeculiarity {
	static User user;

	static {
		user = new User();
		user.setName("校长");
		user.setAge(3);
		user.setSalary(new BigDecimal("123456789.0123"));
	}


	@Test
	public void ceui() {
		//常规
		String jsonString = JSON.toJSONString(user);
		System.out.println("jsonString = " + jsonString);//{"age":3,"name":"校长","salary":123456789.0123}

		//使用单引号
		String jsonString1 = JSON.toJSONString(user, SerializerFeature.UseSingleQuotes);
		System.out.println("jsonString1 = " + jsonString1);//jsonString1 = {'age':3,'name':'校长','salary':123456789.0123}

		//使用单引号,并且对格式进行缩进
		String jsonString2 = JSON.toJSONString(user, SerializerFeature.UseSingleQuotes, SerializerFeature.PrettyFormat);
		System.out.println("jsonString2 = " + jsonString2);
		/*jsonString2 = {
		'age':3,
		'name':'校长',
		'salary':123456789.0123
		}*/


	}

}
